package com.school.HomeWork.ada.Adapter;

// 子系统中的各个组件
public class ClientCom {
    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.on();
    }
}
class Memory {
    public void check() {
        System.out.println("内存自检...");
    }
}

class CPU {
    public void run() {
        System.out.println("CPU运行...");
    }
}

class HardDisk {
    public void read() {
        System.out.println("硬盘读取...");
    }
}

class OS {
    public void load() {
        System.out.println("操作系统加载...");
    }
}

// 外观类
class Computer {
    private Memory memory;
    private CPU cpu;
    private HardDisk hardDisk;
    private OS os;

    public Computer() {
        memory = new Memory();
        cpu = new CPU();
        hardDisk = new HardDisk();
        os = new OS();
    }

    public void on() {
        System.out.println("电脑启动...");
        try {
            memory.check();
            cpu.run();
            hardDisk.read();
            os.load();
            System.out.println("电脑启动成功！");
        } catch (Exception e) {
            System.out.println("电脑启动失败：" + e.getMessage());
        }
    }
}

